{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Example of pipelining with Pandas with `pdpipe`\n",
    "### Dr. Tirthajyoti Sarkar, Fremont, CA, Nov 2019"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import pdpipe as pdp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(\"USA_Housing.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Avg. Area Income</th>\n",
       "      <th>Avg. Area House Age</th>\n",
       "      <th>Avg. Area Number of Rooms</th>\n",
       "      <th>Avg. Area Number of Bedrooms</th>\n",
       "      <th>Area Population</th>\n",
       "      <th>Price</th>\n",
       "      <th>Address</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3274</th>\n",
       "      <td>57944.66</td>\n",
       "      <td>5.77</td>\n",
       "      <td>7.02</td>\n",
       "      <td>4.30</td>\n",
       "      <td>45260.52</td>\n",
       "      <td>1137224.58</td>\n",
       "      <td>357 Hanson Wall Apt. 560\\nFranklinport, SD 426...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3854</th>\n",
       "      <td>70030.02</td>\n",
       "      <td>6.22</td>\n",
       "      <td>7.66</td>\n",
       "      <td>3.05</td>\n",
       "      <td>26782.56</td>\n",
       "      <td>1261715.46</td>\n",
       "      <td>31625 Forbes Terrace Apt. 550\\nMasonview, WY 9...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1671</th>\n",
       "      <td>78963.89</td>\n",
       "      <td>6.86</td>\n",
       "      <td>5.73</td>\n",
       "      <td>3.20</td>\n",
       "      <td>59974.63</td>\n",
       "      <td>2004396.37</td>\n",
       "      <td>9461 Matthew Summit\\nNorth Kathleen, NC 35103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3629</th>\n",
       "      <td>81376.10</td>\n",
       "      <td>7.41</td>\n",
       "      <td>6.00</td>\n",
       "      <td>3.03</td>\n",
       "      <td>40151.93</td>\n",
       "      <td>1788829.24</td>\n",
       "      <td>52901 Griffin Spurs Apt. 216\\nPort Williamches...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3650</th>\n",
       "      <td>70299.02</td>\n",
       "      <td>5.70</td>\n",
       "      <td>6.56</td>\n",
       "      <td>2.00</td>\n",
       "      <td>33147.37</td>\n",
       "      <td>1172619.60</td>\n",
       "      <td>4947 Shawn Greens\\nSouth Crystalville, NJ 68094</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Avg. Area Income  Avg. Area House Age  Avg. Area Number of Rooms  \\\n",
       "3274          57944.66                 5.77                       7.02   \n",
       "3854          70030.02                 6.22                       7.66   \n",
       "1671          78963.89                 6.86                       5.73   \n",
       "3629          81376.10                 7.41                       6.00   \n",
       "3650          70299.02                 5.70                       6.56   \n",
       "\n",
       "      Avg. Area Number of Bedrooms  Area Population       Price  \\\n",
       "3274                          4.30         45260.52  1137224.58   \n",
       "3854                          3.05         26782.56  1261715.46   \n",
       "1671                          3.20         59974.63  2004396.37   \n",
       "3629                          3.03         40151.93  1788829.24   \n",
       "3650                          2.00         33147.37  1172619.60   \n",
       "\n",
       "                                                Address  \n",
       "3274  357 Hanson Wall Apt. 560\\nFranklinport, SD 426...  \n",
       "3854  31625 Forbes Terrace Apt. 550\\nMasonview, WY 9...  \n",
       "1671      9461 Matthew Summit\\nNorth Kathleen, NC 35103  \n",
       "3629  52901 Griffin Spurs Apt. 216\\nPort Williamches...  \n",
       "3650    4947 Shawn Greens\\nSouth Crystalville, NJ 68094  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "round(df.sample(5),2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5000, 7)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Avg. Area Income', 'Avg. Area House Age', 'Avg. Area Number of Rooms',\n",
       "       'Avg. Area Number of Bedrooms', 'Area Population', 'Price', 'Address'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>mean</th>\n",
       "      <th>std</th>\n",
       "      <th>min</th>\n",
       "      <th>25%</th>\n",
       "      <th>50%</th>\n",
       "      <th>75%</th>\n",
       "      <th>max</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Avg. Area Income</th>\n",
       "      <td>5000.0</td>\n",
       "      <td>68583.11</td>\n",
       "      <td>10657.99</td>\n",
       "      <td>17796.63</td>\n",
       "      <td>61480.56</td>\n",
       "      <td>68804.29</td>\n",
       "      <td>75783.34</td>\n",
       "      <td>107701.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Avg. Area House Age</th>\n",
       "      <td>5000.0</td>\n",
       "      <td>5.98</td>\n",
       "      <td>0.99</td>\n",
       "      <td>2.64</td>\n",
       "      <td>5.32</td>\n",
       "      <td>5.97</td>\n",
       "      <td>6.65</td>\n",
       "      <td>9.52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Avg. Area Number of Rooms</th>\n",
       "      <td>5000.0</td>\n",
       "      <td>6.99</td>\n",
       "      <td>1.01</td>\n",
       "      <td>3.24</td>\n",
       "      <td>6.30</td>\n",
       "      <td>7.00</td>\n",
       "      <td>7.67</td>\n",
       "      <td>10.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Avg. Area Number of Bedrooms</th>\n",
       "      <td>5000.0</td>\n",
       "      <td>3.98</td>\n",
       "      <td>1.23</td>\n",
       "      <td>2.00</td>\n",
       "      <td>3.14</td>\n",
       "      <td>4.05</td>\n",
       "      <td>4.49</td>\n",
       "      <td>6.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Area Population</th>\n",
       "      <td>5000.0</td>\n",
       "      <td>36163.52</td>\n",
       "      <td>9925.65</td>\n",
       "      <td>172.61</td>\n",
       "      <td>29403.93</td>\n",
       "      <td>36199.41</td>\n",
       "      <td>42861.29</td>\n",
       "      <td>69621.71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Price</th>\n",
       "      <td>5000.0</td>\n",
       "      <td>1232072.65</td>\n",
       "      <td>353117.63</td>\n",
       "      <td>15938.66</td>\n",
       "      <td>997577.14</td>\n",
       "      <td>1232669.38</td>\n",
       "      <td>1471210.20</td>\n",
       "      <td>2469065.59</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               count        mean        std       min  \\\n",
       "Avg. Area Income              5000.0    68583.11   10657.99  17796.63   \n",
       "Avg. Area House Age           5000.0        5.98       0.99      2.64   \n",
       "Avg. Area Number of Rooms     5000.0        6.99       1.01      3.24   \n",
       "Avg. Area Number of Bedrooms  5000.0        3.98       1.23      2.00   \n",
       "Area Population               5000.0    36163.52    9925.65    172.61   \n",
       "Price                         5000.0  1232072.65  353117.63  15938.66   \n",
       "\n",
       "                                    25%         50%         75%         max  \n",
       "Avg. Area Income               61480.56    68804.29    75783.34   107701.75  \n",
       "Avg. Area House Age                5.32        5.97        6.65        9.52  \n",
       "Avg. Area Number of Rooms          6.30        7.00        7.67       10.76  \n",
       "Avg. Area Number of Bedrooms       3.14        4.05        4.49        6.50  \n",
       "Area Population                29403.93    36199.41    42861.29    69621.71  \n",
       "Price                         997577.14  1232669.38  1471210.20  2469065.59  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "round(df.describe().T,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def size(n):\n",
    "    if n<=4:\n",
    "        return 'Small'\n",
    "    elif 4<n<=6:\n",
    "        return 'Medium'\n",
    "    else:\n",
    "        return 'Big'\n",
    "\n",
    "df['House_size']=df['Avg. Area Number of Rooms'].apply(size)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['House_size']=df['Avg. Area Number of Rooms'].apply(size)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Avg. Area Income</th>\n",
       "      <th>Avg. Area House Age</th>\n",
       "      <th>Avg. Area Number of Rooms</th>\n",
       "      <th>Avg. Area Number of Bedrooms</th>\n",
       "      <th>Area Population</th>\n",
       "      <th>Price</th>\n",
       "      <th>Address</th>\n",
       "      <th>House_size</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3920</th>\n",
       "      <td>66749.57</td>\n",
       "      <td>7.16</td>\n",
       "      <td>6.10</td>\n",
       "      <td>3.37</td>\n",
       "      <td>46553.98</td>\n",
       "      <td>1394637.65</td>\n",
       "      <td>1630 Castillo Summit Apt. 619\\nEast Karenborou...</td>\n",
       "      <td>Big</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2267</th>\n",
       "      <td>76992.82</td>\n",
       "      <td>6.53</td>\n",
       "      <td>6.05</td>\n",
       "      <td>4.46</td>\n",
       "      <td>24874.04</td>\n",
       "      <td>1212440.29</td>\n",
       "      <td>8188 Henry Gardens\\nPort Rogerberg, OK 27962-5231</td>\n",
       "      <td>Big</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4302</th>\n",
       "      <td>61877.55</td>\n",
       "      <td>5.55</td>\n",
       "      <td>6.80</td>\n",
       "      <td>3.25</td>\n",
       "      <td>28604.94</td>\n",
       "      <td>1083745.37</td>\n",
       "      <td>03529 Hull Mountains\\nLake Zacharyshire, WY 94496</td>\n",
       "      <td>Big</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4320</th>\n",
       "      <td>64426.87</td>\n",
       "      <td>5.50</td>\n",
       "      <td>8.95</td>\n",
       "      <td>3.31</td>\n",
       "      <td>18214.31</td>\n",
       "      <td>1055548.68</td>\n",
       "      <td>Unit 4466 Box 0788\\nDPO AP 45943</td>\n",
       "      <td>Big</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1796</th>\n",
       "      <td>78159.95</td>\n",
       "      <td>5.12</td>\n",
       "      <td>6.18</td>\n",
       "      <td>4.08</td>\n",
       "      <td>31111.62</td>\n",
       "      <td>1264972.44</td>\n",
       "      <td>3276 Harris Pines Suite 433\\nPort Paul, NY 662...</td>\n",
       "      <td>Big</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Avg. Area Income  Avg. Area House Age  Avg. Area Number of Rooms  \\\n",
       "3920          66749.57                 7.16                       6.10   \n",
       "2267          76992.82                 6.53                       6.05   \n",
       "4302          61877.55                 5.55                       6.80   \n",
       "4320          64426.87                 5.50                       8.95   \n",
       "1796          78159.95                 5.12                       6.18   \n",
       "\n",
       "      Avg. Area Number of Bedrooms  Area Population       Price  \\\n",
       "3920                          3.37         46553.98  1394637.65   \n",
       "2267                          4.46         24874.04  1212440.29   \n",
       "4302                          3.25         28604.94  1083745.37   \n",
       "4320                          3.31         18214.31  1055548.68   \n",
       "1796                          4.08         31111.62  1264972.44   \n",
       "\n",
       "                                                Address House_size  \n",
       "3920  1630 Castillo Summit Apt. 619\\nEast Karenborou...        Big  \n",
       "2267  8188 Henry Gardens\\nPort Rogerberg, OK 27962-5231        Big  \n",
       "4302  03529 Hull Mountains\\nLake Zacharyshire, WY 94496        Big  \n",
       "4320                   Unit 4466 Box 0788\\nDPO AP 45943        Big  \n",
       "1796  3276 Harris Pines Suite 433\\nPort Paul, NY 662...        Big  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "round(df.sample(5),2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Drop a column"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "drop_age = pdp.ColDrop('Avg. Area House Age')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "df2 = drop_age(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Avg. Area Income</th>\n",
       "      <th>Avg. Area Number of Rooms</th>\n",
       "      <th>Avg. Area Number of Bedrooms</th>\n",
       "      <th>Area Population</th>\n",
       "      <th>Price</th>\n",
       "      <th>Address</th>\n",
       "      <th>House_size</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1384</th>\n",
       "      <td>43922.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>42251.0</td>\n",
       "      <td>747933.0</td>\n",
       "      <td>3112 Wells Parkway Apt. 414\\nSouth Emilycheste...</td>\n",
       "      <td>Big</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2442</th>\n",
       "      <td>43242.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>29479.0</td>\n",
       "      <td>629658.0</td>\n",
       "      <td>860 Graham Meadows Suite 412\\nEast Kristenburg...</td>\n",
       "      <td>Big</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2395</th>\n",
       "      <td>73612.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>38294.0</td>\n",
       "      <td>1487856.0</td>\n",
       "      <td>827 Christina Divide\\nNew Tanya, MO 26789-8710</td>\n",
       "      <td>Big</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2768</th>\n",
       "      <td>51928.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>32257.0</td>\n",
       "      <td>970177.0</td>\n",
       "      <td>8889 Ashley Dale\\nNorth Robertmouth, IA 68137-...</td>\n",
       "      <td>Big</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4820</th>\n",
       "      <td>50442.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>33440.0</td>\n",
       "      <td>644142.0</td>\n",
       "      <td>0645 Arroyo Trail\\nEast Michelle, LA 07906-8981</td>\n",
       "      <td>Big</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Avg. Area Income  Avg. Area Number of Rooms  \\\n",
       "1384           43922.0                        7.0   \n",
       "2442           43242.0                        7.0   \n",
       "2395           73612.0                        8.0   \n",
       "2768           51928.0                        7.0   \n",
       "4820           50442.0                        7.0   \n",
       "\n",
       "      Avg. Area Number of Bedrooms  Area Population      Price  \\\n",
       "1384                           5.0          42251.0   747933.0   \n",
       "2442                           2.0          29479.0   629658.0   \n",
       "2395                           4.0          38294.0  1487856.0   \n",
       "2768                           6.0          32257.0   970177.0   \n",
       "4820                           6.0          33440.0   644142.0   \n",
       "\n",
       "                                                Address House_size  \n",
       "1384  3112 Wells Parkway Apt. 414\\nSouth Emilycheste...        Big  \n",
       "2442  860 Graham Meadows Suite 412\\nEast Kristenburg...        Big  \n",
       "2395     827 Christina Divide\\nNew Tanya, MO 26789-8710        Big  \n",
       "2768  8889 Ashley Dale\\nNorth Robertmouth, IA 68137-...        Big  \n",
       "4820    0645 Arroyo Trail\\nEast Michelle, LA 07906-8981        Big  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "round(df2.sample(5))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Chaining stages by adding them up"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "pipeline = pdp.ColDrop('Avg. Area House Age')\n",
    "pipeline+= pdp.OneHotEncode('House_size')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "df3 = pipeline(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Avg. Area Income</th>\n",
       "      <th>Avg. Area Number of Rooms</th>\n",
       "      <th>Avg. Area Number of Bedrooms</th>\n",
       "      <th>Area Population</th>\n",
       "      <th>Price</th>\n",
       "      <th>Address</th>\n",
       "      <th>House_size_Medium</th>\n",
       "      <th>House_size_Small</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1534</th>\n",
       "      <td>59902.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>30211.0</td>\n",
       "      <td>1088549.0</td>\n",
       "      <td>343 Samuel Pass Suite 476\\nKimberlyberg, ME 70939</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1682</th>\n",
       "      <td>64750.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>49537.0</td>\n",
       "      <td>1781211.0</td>\n",
       "      <td>4293 Abigail Tunnel\\nWest Brandi, ND 75636</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>502</th>\n",
       "      <td>90437.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>13340.0</td>\n",
       "      <td>1647279.0</td>\n",
       "      <td>PSC 8841, Box 4711\\nAPO AA 80496-2707</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1069</th>\n",
       "      <td>82185.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>29259.0</td>\n",
       "      <td>1162735.0</td>\n",
       "      <td>Unit 4395 Box 2223\\nDPO AE 68423-9498</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4052</th>\n",
       "      <td>82115.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>46052.0</td>\n",
       "      <td>1796532.0</td>\n",
       "      <td>591 Fernandez Ports\\nNorth Angelaside, MP 72848</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Avg. Area Income  Avg. Area Number of Rooms  \\\n",
       "1534           59902.0                        8.0   \n",
       "1682           64750.0                        8.0   \n",
       "502            90437.0                        8.0   \n",
       "1069           82185.0                        5.0   \n",
       "4052           82115.0                        7.0   \n",
       "\n",
       "      Avg. Area Number of Bedrooms  Area Population      Price  \\\n",
       "1534                           6.0          30211.0  1088549.0   \n",
       "1682                           4.0          49537.0  1781211.0   \n",
       "502                            6.0          13340.0  1647279.0   \n",
       "1069                           4.0          29259.0  1162735.0   \n",
       "4052                           4.0          46052.0  1796532.0   \n",
       "\n",
       "                                                Address  House_size_Medium  \\\n",
       "1534  343 Samuel Pass Suite 476\\nKimberlyberg, ME 70939                  0   \n",
       "1682         4293 Abigail Tunnel\\nWest Brandi, ND 75636                  0   \n",
       "502               PSC 8841, Box 4711\\nAPO AA 80496-2707                  0   \n",
       "1069              Unit 4395 Box 2223\\nDPO AE 68423-9498                  1   \n",
       "4052    591 Fernandez Ports\\nNorth Angelaside, MP 72848                  0   \n",
       "\n",
       "      House_size_Small  \n",
       "1534                 0  \n",
       "1682                 0  \n",
       "502                  0  \n",
       "1069                 0  \n",
       "4052                 0  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "round(df3.sample(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "def price_tag(x):\n",
    "    if x>250000:\n",
    "        return 'keep'\n",
    "    else:\n",
    "        return 'drop'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "pipeline = pdp.ColDrop('Avg. Area House Age')\n",
    "pipeline+= pdp.OneHotEncode('House_size')\n",
    "pipeline+=pdp.ApplyByCols('Price',price_tag,'Price_tag',drop=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "df4 = pipeline(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5000, 9)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df4.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Avg. Area Income</th>\n",
       "      <th>Avg. Area Number of Rooms</th>\n",
       "      <th>Avg. Area Number of Bedrooms</th>\n",
       "      <th>Area Population</th>\n",
       "      <th>Price</th>\n",
       "      <th>Price_tag</th>\n",
       "      <th>Address</th>\n",
       "      <th>House_size_Medium</th>\n",
       "      <th>House_size_Small</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4512</th>\n",
       "      <td>71162.38</td>\n",
       "      <td>7.22</td>\n",
       "      <td>3.40</td>\n",
       "      <td>39134.55</td>\n",
       "      <td>1434240.36</td>\n",
       "      <td>keep</td>\n",
       "      <td>4619 Angela Rest Apt. 586\\nPaulport, IL 15870</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2125</th>\n",
       "      <td>75434.55</td>\n",
       "      <td>8.25</td>\n",
       "      <td>4.04</td>\n",
       "      <td>43181.91</td>\n",
       "      <td>1613325.65</td>\n",
       "      <td>keep</td>\n",
       "      <td>746 Steele Terrace Suite 937\\nHughesborough, M...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2304</th>\n",
       "      <td>72110.50</td>\n",
       "      <td>7.05</td>\n",
       "      <td>5.33</td>\n",
       "      <td>23411.95</td>\n",
       "      <td>1208761.06</td>\n",
       "      <td>keep</td>\n",
       "      <td>952 Richard Spring Apt. 574\\nMoniquemouth, WA ...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3366</th>\n",
       "      <td>72261.20</td>\n",
       "      <td>7.35</td>\n",
       "      <td>3.07</td>\n",
       "      <td>42681.82</td>\n",
       "      <td>1568433.33</td>\n",
       "      <td>keep</td>\n",
       "      <td>367 Christopher Isle\\nNew Tina, MO 23475-8112</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3916</th>\n",
       "      <td>46285.84</td>\n",
       "      <td>8.76</td>\n",
       "      <td>3.42</td>\n",
       "      <td>42246.02</td>\n",
       "      <td>1153321.60</td>\n",
       "      <td>keep</td>\n",
       "      <td>4366 Lewis Crescent Suite 780\\nPaynefurt, VT 6...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Avg. Area Income  Avg. Area Number of Rooms  \\\n",
       "4512          71162.38                       7.22   \n",
       "2125          75434.55                       8.25   \n",
       "2304          72110.50                       7.05   \n",
       "3366          72261.20                       7.35   \n",
       "3916          46285.84                       8.76   \n",
       "\n",
       "      Avg. Area Number of Bedrooms  Area Population       Price Price_tag  \\\n",
       "4512                          3.40         39134.55  1434240.36      keep   \n",
       "2125                          4.04         43181.91  1613325.65      keep   \n",
       "2304                          5.33         23411.95  1208761.06      keep   \n",
       "3366                          3.07         42681.82  1568433.33      keep   \n",
       "3916                          3.42         42246.02  1153321.60      keep   \n",
       "\n",
       "                                                Address  House_size_Medium  \\\n",
       "4512      4619 Angela Rest Apt. 586\\nPaulport, IL 15870                  0   \n",
       "2125  746 Steele Terrace Suite 937\\nHughesborough, M...                  0   \n",
       "2304  952 Richard Spring Apt. 574\\nMoniquemouth, WA ...                  0   \n",
       "3366      367 Christopher Isle\\nNew Tina, MO 23475-8112                  0   \n",
       "3916  4366 Lewis Crescent Suite 780\\nPaynefurt, VT 6...                  0   \n",
       "\n",
       "      House_size_Small  \n",
       "4512                 0  \n",
       "2125                 0  \n",
       "2304                 0  \n",
       "3366                 0  \n",
       "3916                 0  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "round(df4.sample(5),2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "pipeline = pdp.ColDrop('Avg. Area House Age')\n",
    "pipeline+= pdp.OneHotEncode('House_size')\n",
    "pipeline+=pdp.ApplyByCols('Price',price_tag,'Price_tag',drop=False)\n",
    "pipeline+=pdp.ValDrop(['drop'],'Price_tag')\n",
    "pipeline+= pdp.ColDrop('Price_tag')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "df5 = pipeline(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4990, 8)"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df5.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Scikit-learn scaling"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "pipeline_scale = pdp.Scale('StandardScaler',exclude_columns=['House_size_Medium','House_size_Small'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "df6 = pipeline_scale(df5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Avg. Area Income</th>\n",
       "      <th>Avg. Area Number of Rooms</th>\n",
       "      <th>Avg. Area Number of Bedrooms</th>\n",
       "      <th>Area Population</th>\n",
       "      <th>Price</th>\n",
       "      <th>Address</th>\n",
       "      <th>House_size_Medium</th>\n",
       "      <th>House_size_Small</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2063</th>\n",
       "      <td>2.067</td>\n",
       "      <td>-1.195</td>\n",
       "      <td>-1.379</td>\n",
       "      <td>-0.128</td>\n",
       "      <td>1.366</td>\n",
       "      <td>06374 Martin Passage\\nNew Shawnland, KS 59839-...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1001</th>\n",
       "      <td>-0.183</td>\n",
       "      <td>0.504</td>\n",
       "      <td>0.840</td>\n",
       "      <td>-1.328</td>\n",
       "      <td>-1.849</td>\n",
       "      <td>827 Ferguson Isle\\nRosebury, AL 61416-3167</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3801</th>\n",
       "      <td>0.044</td>\n",
       "      <td>0.062</td>\n",
       "      <td>1.164</td>\n",
       "      <td>-0.352</td>\n",
       "      <td>0.300</td>\n",
       "      <td>Unit 8410 Box 5521\\nDPO AP 20914-6877</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4690</th>\n",
       "      <td>1.528</td>\n",
       "      <td>-0.738</td>\n",
       "      <td>0.071</td>\n",
       "      <td>0.123</td>\n",
       "      <td>0.048</td>\n",
       "      <td>29600 Garcia Forest Suite 239\\nWest Mark, NV 5...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3797</th>\n",
       "      <td>-1.155</td>\n",
       "      <td>-2.088</td>\n",
       "      <td>-1.443</td>\n",
       "      <td>-1.283</td>\n",
       "      <td>-1.671</td>\n",
       "      <td>1629 James Pines\\nPort John, LA 49420</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Avg. Area Income  Avg. Area Number of Rooms  \\\n",
       "2063             2.067                     -1.195   \n",
       "1001            -0.183                      0.504   \n",
       "3801             0.044                      0.062   \n",
       "4690             1.528                     -0.738   \n",
       "3797            -1.155                     -2.088   \n",
       "\n",
       "      Avg. Area Number of Bedrooms  Area Population  Price  \\\n",
       "2063                        -1.379           -0.128  1.366   \n",
       "1001                         0.840           -1.328 -1.849   \n",
       "3801                         1.164           -0.352  0.300   \n",
       "4690                         0.071            0.123  0.048   \n",
       "3797                        -1.443           -1.283 -1.671   \n",
       "\n",
       "                                                Address  House_size_Medium  \\\n",
       "2063  06374 Martin Passage\\nNew Shawnland, KS 59839-...                  1   \n",
       "1001         827 Ferguson Isle\\nRosebury, AL 61416-3167                  0   \n",
       "3801              Unit 8410 Box 5521\\nDPO AP 20914-6877                  0   \n",
       "4690  29600 Garcia Forest Suite 239\\nWest Mark, NV 5...                  0   \n",
       "3797              1629 James Pines\\nPort John, LA 49420                  1   \n",
       "\n",
       "      House_size_Small  \n",
       "2063                 0  \n",
       "1001                 0  \n",
       "3801                 0  \n",
       "4690                 0  \n",
       "3797                 0  "
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "round(df6.sample(5),3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### NLTK stages"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "pipeline_tokenize=pdp.TokenizeWords('Address')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "df7 = pipeline_tokenize(df6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Avg. Area Income</th>\n",
       "      <th>Avg. Area Number of Rooms</th>\n",
       "      <th>Avg. Area Number of Bedrooms</th>\n",
       "      <th>Area Population</th>\n",
       "      <th>Price</th>\n",
       "      <th>Address</th>\n",
       "      <th>House_size_Medium</th>\n",
       "      <th>House_size_Small</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2801</th>\n",
       "      <td>-2.163790</td>\n",
       "      <td>-0.161473</td>\n",
       "      <td>-1.322010</td>\n",
       "      <td>0.623847</td>\n",
       "      <td>-0.359488</td>\n",
       "      <td>[525, Ashley, Course, Lake, Michelleville, ,, ...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>646</th>\n",
       "      <td>-0.182429</td>\n",
       "      <td>-0.023628</td>\n",
       "      <td>-1.573084</td>\n",
       "      <td>0.104469</td>\n",
       "      <td>-0.187608</td>\n",
       "      <td>[8961, Guerra, Motorway, Stephensburgh, ,, AR,...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>838</th>\n",
       "      <td>-0.569561</td>\n",
       "      <td>0.185986</td>\n",
       "      <td>0.314022</td>\n",
       "      <td>0.532345</td>\n",
       "      <td>-0.206402</td>\n",
       "      <td>[86533, Gould, Hills, Garciachester, ,, DE, 09...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4409</th>\n",
       "      <td>-0.320249</td>\n",
       "      <td>0.464002</td>\n",
       "      <td>0.014353</td>\n",
       "      <td>-1.373439</td>\n",
       "      <td>-0.458186</td>\n",
       "      <td>[089, Smith, Gateway, Suite, 155, East, Christ...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1983</th>\n",
       "      <td>-0.004935</td>\n",
       "      <td>-0.580628</td>\n",
       "      <td>0.087245</td>\n",
       "      <td>0.836355</td>\n",
       "      <td>-0.598361</td>\n",
       "      <td>[Unit, 8667, Box, 6237, DPO, AE, 76811-0261]</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Avg. Area Income  Avg. Area Number of Rooms  \\\n",
       "2801         -2.163790                  -0.161473   \n",
       "646          -0.182429                  -0.023628   \n",
       "838          -0.569561                   0.185986   \n",
       "4409         -0.320249                   0.464002   \n",
       "1983         -0.004935                  -0.580628   \n",
       "\n",
       "      Avg. Area Number of Bedrooms  Area Population     Price  \\\n",
       "2801                     -1.322010         0.623847 -0.359488   \n",
       "646                      -1.573084         0.104469 -0.187608   \n",
       "838                       0.314022         0.532345 -0.206402   \n",
       "4409                      0.014353        -1.373439 -0.458186   \n",
       "1983                      0.087245         0.836355 -0.598361   \n",
       "\n",
       "                                                Address  House_size_Medium  \\\n",
       "2801  [525, Ashley, Course, Lake, Michelleville, ,, ...                  0   \n",
       "646   [8961, Guerra, Motorway, Stephensburgh, ,, AR,...                  0   \n",
       "838   [86533, Gould, Hills, Garciachester, ,, DE, 09...                  0   \n",
       "4409  [089, Smith, Gateway, Suite, 155, East, Christ...                  0   \n",
       "1983       [Unit, 8667, Box, 6237, DPO, AE, 76811-0261]                  0   \n",
       "\n",
       "      House_size_Small  \n",
       "2801                 0  \n",
       "646                  0  \n",
       "838                  0  \n",
       "4409                 0  \n",
       "1983                 0  "
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df7.sample(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "def extract_state(token):\n",
    "    return str(token[-2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "pipeline_state = pdp.ApplyByCols('Address',extract_state,result_columns='State')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "df8=pipeline_state(df7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Avg. Area Income</th>\n",
       "      <th>Avg. Area Number of Rooms</th>\n",
       "      <th>Avg. Area Number of Bedrooms</th>\n",
       "      <th>Area Population</th>\n",
       "      <th>Price</th>\n",
       "      <th>State</th>\n",
       "      <th>House_size_Medium</th>\n",
       "      <th>House_size_Small</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2150</th>\n",
       "      <td>-0.902</td>\n",
       "      <td>0.709</td>\n",
       "      <td>1.156</td>\n",
       "      <td>-1.005</td>\n",
       "      <td>-1.566</td>\n",
       "      <td>AA</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2330</th>\n",
       "      <td>0.042</td>\n",
       "      <td>0.092</td>\n",
       "      <td>-0.698</td>\n",
       "      <td>-0.412</td>\n",
       "      <td>-0.481</td>\n",
       "      <td>GU</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3717</th>\n",
       "      <td>-1.454</td>\n",
       "      <td>0.991</td>\n",
       "      <td>1.011</td>\n",
       "      <td>-0.755</td>\n",
       "      <td>-1.877</td>\n",
       "      <td>CO</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4187</th>\n",
       "      <td>-0.242</td>\n",
       "      <td>0.962</td>\n",
       "      <td>0.865</td>\n",
       "      <td>-0.975</td>\n",
       "      <td>-1.690</td>\n",
       "      <td>WV</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>260</th>\n",
       "      <td>-0.701</td>\n",
       "      <td>0.098</td>\n",
       "      <td>0.930</td>\n",
       "      <td>-0.989</td>\n",
       "      <td>-0.345</td>\n",
       "      <td>NV</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Avg. Area Income  Avg. Area Number of Rooms  \\\n",
       "2150            -0.902                      0.709   \n",
       "2330             0.042                      0.092   \n",
       "3717            -1.454                      0.991   \n",
       "4187            -0.242                      0.962   \n",
       "260             -0.701                      0.098   \n",
       "\n",
       "      Avg. Area Number of Bedrooms  Area Population  Price State  \\\n",
       "2150                         1.156           -1.005 -1.566    AA   \n",
       "2330                        -0.698           -0.412 -0.481    GU   \n",
       "3717                         1.011           -0.755 -1.877    CO   \n",
       "4187                         0.865           -0.975 -1.690    WV   \n",
       "260                          0.930           -0.989 -0.345    NV   \n",
       "\n",
       "      House_size_Medium  House_size_Small  \n",
       "2150                  0                 0  \n",
       "2330                  0                 0  \n",
       "3717                  0                 0  \n",
       "4187                  0                 0  \n",
       "260                   0                 0  "
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "round(df8.sample(5),3)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
